package com.zhouyong.leetcode.对称二叉树101;

import com.zhouyong.leetcode.TreeNode;
import sun.reflect.generics.tree.Tree;

/**
 * @Author 99
 * @Date 2022/10/4 11:55
 * @Version 1.0
 */
public class Test {

    // 给你一个二叉树的根节点 root ， 检查它是否轴对称。
    // 输入：root = [1,2,2,3,4,4,3]
    // 输出：true
    public static void main(String[] args) {
        TreeNode p = new TreeNode(1, new TreeNode(2, new TreeNode(3), new TreeNode(4)), new TreeNode(2, new TreeNode(4), new TreeNode(3)));
        System.out.println(isSymmetric(p));
    }

    public static boolean isSymmetric(TreeNode root) {
        return isSymmetry(root, root);
    }

    public static boolean isSymmetry(TreeNode a, TreeNode b) {
        if (a == null && b == null) {
            return true;
        }
        if (a == null || b == null) {
            return false;
        }
        return a.val == b.val && isSymmetry(a.left, b.right) && isSymmetry(a.right, b.left);
    }
}
